package com.lovo.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.project.bean.RoleBean;
import com.lovo.project.bean.UserBean;
import com.lovo.project.mapper.RoleMapper;
import com.lovo.project.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, RoleBean> implements RoleService {
    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<RoleBean> selectRoleList() {
        List<RoleBean> list=roleMapper.selectList(null);
        return list;
    }

    @Override
    public List<RoleBean> queryUserRoleList(Integer userId) {
    List<RoleBean> list=roleMapper.selectUserRole(userId);
        return list;
    }

    @Override
    public void updateUserRole(Integer userId, List<Integer> roleId) {
        roleMapper.deleteUserRole(userId);
        roleMapper.insertUserRole(userId,roleId);
    }

    @Override
    public void deleteRole(Integer roleId) {
        roleMapper.deleteById(roleId);
    }

    @Override
    public Page<RoleBean> selectRoleList1(Page<RoleBean> page, QueryWrapper queryWrapper) {
        Page<RoleBean> page1=roleMapper.selectPage(page,null);
        return page1;
    }

    @Override
    public RoleBean queryRole(Integer roleId) {
        RoleBean roleBean=roleMapper.selectById(roleId);
        return roleBean;
    }
}
